package com.example.demo.algorithm;

import java.util.Arrays;

/**
 * 项目名称：hello-6
 * 类 名 称：ShellSort1
 * 类 描 述：希尔排序
 * 创建时间：2020/11/26 22:39
 * 创 建 人：wangsheng
 */
public class ShellSort1 {

    public static void main(String[] args) {
        int[] arrays = {99, 5, 69, 33, 56, 13, 22, 55, 77, 48, 12, 88, 2, 69, 99};
        //增量每次都/2
        for (int step = arrays.length / 2; step > 0; step /= 2) {

            //从增量那组开始进行插入排序，直至完毕
            for (int i = step; i < arrays.length; i++) {

                int j = i;
                int temp = arrays[j];

                // j - step 就是代表与它同组隔壁的元素
                while (j - step >= 0 && arrays[j - step] > temp) {
                    arrays[j] = arrays[j - step];
                    j = j - step;
                }
                arrays[j] = temp;
            }
        }
        System.out.println(Arrays.toString(arrays));
    }
}
